/**
 * 
 *
 * 
 * You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 */
package ME2AND;

import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;

/** Auto generated stub code from a class file */
public class Font {

  public static final int STYLE_PLAIN = 0;
  public static final int STYLE_BOLD = 1;
  public static final int STYLE_ITALIC = 2;
  public static final int STYLE_UNDERLINED = 4;
  public static final int SIZE_SMALL = 8;
  public static final int SIZE_MEDIUM = 0;
  public static final int SIZE_LARGE = 16;
  public static final int FACE_SYSTEM = 0;
  public static final int FACE_MONOSPACE = 32;
  public static final int FACE_PROPORTIONAL = 64;
  public static final int FONT_STATIC_TEXT = 0;
  public static final int FONT_INPUT_TEXT = 1;
  
  private Typeface face;
  private int size;
  private int faceI;
  private int style;
  private Paint holdPaint;
  private Paint.FontMetrics metrics;

  public Font(int size, int face, int style) {
	  this.size = size;
	  this.faceI = face;
	  this.style = style;
	  
	  Typeface family = Typeface.SANS_SERIF;
	  
	  switch(face) {
	  
	  	case FACE_SYSTEM:
	  	case FACE_MONOSPACE:
	  		family = Typeface.MONOSPACE;
	  
	  }
	  	  
	  int typeStyle = Typeface.NORMAL;
	  
	  if((style & STYLE_BOLD) > 0) {
		  typeStyle |= Typeface.BOLD;
	  }
	  if((style & STYLE_ITALIC) > 0) {
		  typeStyle |= Typeface.ITALIC;
	  }
	  
	  this.face = Typeface.create(family, typeStyle);	  
	  _loadPaint(new Paint(0));
  }
  
  /**
   * Loads this fonts settings into a paint object
   * @param p
   */
  public void _loadPaint(Paint p) {
	  p.setTypeface(this.face);
	  
	  switch (size) {
		  case SIZE_SMALL:
			  p.setTextSize(14);
			  break;
		  case SIZE_MEDIUM:
			  p.setTextSize(18);
			  break;
		  case SIZE_LARGE:
			  p.setTextSize(20);
			  break;
	  }
	  metrics = p.getFontMetrics();
	  holdPaint = p;
  }
  
  public static Font getFont(int i0) {
    return getDefaultFont();
  }

  public static Font getDefaultFont() {
    return Font.getFont(FACE_PROPORTIONAL, 0, SIZE_MEDIUM);
  }

  public static Font getFont(int face, int style, int size) {
	  Font font = new Font(size, face, style);
	  return font;
  }

  public int getStyle() {
    return style;
  }

  public int getSize() {
    return size;
  }

  public int getFace() {
    return faceI;
  }

  public boolean isPlain() {
    return (faceI == 0);
  }

  public boolean isBold() {
    return (faceI & STYLE_BOLD) > 0;
  }

  public boolean isItalic() {
    return (faceI & STYLE_ITALIC) > 0;
  }

  public boolean isUnderlined() {
    return false;
  }

  public int getHeight() {
	  //TODO work out better height value
//    return Math.round((metrics.top + metrics.bottom + metrics.leading) * 1.5f) + 1;
	  
	  return Math.abs(Math.round((metrics.top + metrics.bottom + metrics.leading) * 1.5f) + 1);
  }

  public int getBaselinePosition() {
    return 0;
  }

  public int charWidth(char c) {
	Rect r = new Rect();
	holdPaint.getTextBounds(new char[] { c }, 0, 1, r);
	int width = r.right; //Math.round(r.right);
    return width;
  }

  public int charsWidth(char[] c, int offs, int len) {
	  Rect r = new Rect();
	  holdPaint.getTextBounds(c, offs, len, r);
	  int width = r.right; //Math.round(r.right);	  
	  return width;
  }

  public int stringWidth(String o0) {
	  return substringWidth(o0, 0, o0.length());
  }

  public int substringWidth(String o0, int i1, int i2) {
	  Rect r = new Rect();
	  holdPaint.getTextBounds(o0, i1, i2, r);
	  int width = r.right; //Math.round(r.right);	  
	  return width;
  }

}

